<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>综合服务 考试人员</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--JQ-->
    <script type="text/javascript" charset="utf-8"
            src="${re.contextPath}/plugin/common/js/jquery-1.8.3.min.js"></script>
    <!--Layui-->
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/common/js/comment.js" charset="utf-8"></script>
    <style>
        .layui-laypage-limits>select{
            width: 100% !important;
        }
        .layui-col-md4 {
            width: 100%;
        }

        select {
            height: 38px;
            margin-right: 10px
        }

        .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #1E9FFF;
        }
    </style>
</head>

<body>
<!--容器-->

<div class="container index clearfix">
    <!--右侧内容-->
    <div class="Right fr" style="width: 100%;">
        <div  lay-filter="docDemoTabBrief" style="margin-top: 12px;">
            <div style="background-color: #F1F4FB;border-radius: 5px;padding:14px 10px;">
                <div class="layui-row">
                    <div class="layui-col-md4" style="padding-left:1%">
                        <input type="hidden" id="examId" name="examId" value="${examId}">
                        <input id="realName" class="layui-input layui-input-inline" type="text" placeholder="请输入姓名" style="width: 20%;box-sizing: border-box;">
                        <select name="deptId" class="ml8 fl" id="deptId" style="width: 20%;"
                                lay-ignore>
                            <option value="">请选择部门</option>
                            <#list deptList as vo>
                                <option value="${vo.badtCode}"
                                >${vo.badtName}</option>
                            </#list>
                        </select>
                        <select name="companyId" class="ml8 fl" id="companyId" style="width: 20%;"
                                lay-ignore>
                            <option value="">所属公司</option>
                            <#list companyList as vo>
                                <option value="${vo.bcId}"
                                >${vo.bcName}</option>
                            </#list>
                        </select>
                        <select name="roleId" class="ml8 fl" id="roleId" style="width: 20%;"
                                lay-ignore>
                            <option value="">角色</option>
                            <#list js as vo>
                                <option value="${vo.id}"
                                >${vo.remark}</option>
                            </#list>
                        </select>
                        <#--				<input class="layui-btn layui-btn-danger layui-btn-sm fr ml10" type="button" value="重置" onclick="resetQuery()">-->
                        <input class="layui-btn layui-btn-normal fr" type="button" value="筛选" onclick="query()">
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<div class="layui-container"
     style="background-color: #ffffff;width:96%;padding:16px;border-radius: 10px">
    <div class="layui-row" style="width: 100%;text-align: center">
        <table id="tableList" class="layui-hide" lay-filter="tableList"></table>
        <button type="button" class="layui-btn layui-btn-normal white ft18 close" onclick="closes()">取消</button>
        <button type="button" lay-submit class="layui-btn layui-btn-normal bluebg white ft18 " onclick="add()">保存</button>
        <span>已选中人数:</span><input type="text" id="amount" disabled>
    </div>

</div>
<script type="text/javascript" src="${re.contextPath}/pageoffice.js" id="po_js_main"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script>
    var layer;
    var tableIns;
    var table;
    var memberArr = [];
    $(function () {
        layui.use(['table'], function () {
            table = layui.table;
            form = layui.form;
            let $ = layui.$;
            let ids = [];
            let tableIds = [];
            //方法级渲染
            tableIns = table.render({
                id: 'tableList',
                elem: '#tableList',
                url: '/exam/list/selectUser?examId='+$("#examId").val(),
                page: true,
                cols: [[
                    {type:'checkbox'},
                    {
                        title: '序号', width: '10%', templet: function (res) {
                            return res.LAY_INDEX;
                        }
                    },
                    {field: 'id', title: 'ID', hide: true, sort: false},
                    {field: 'realName', title: '姓名', width: '40%', sort: false},
                    {field: 'deptName', title: '部门', width: '46.4%', sort: false},
                ]],
                done: function (res) {
                    tableIds = res.data.map(function (val) {
                        return val.id;
                    })

                    $.each(res.data, function (idx, val) {
                        if (ids.indexOf(val.id) > -1) {
                            val["LAY_CHECKED"] = 'true';
                            let index = val['LAY_TABLE_INDEX'];
                            $('tr[data-index=' + index + '] input[type="checkbox"]').click();
                            form.render('checkbox');
                        }
                    })

                    let checkStatus = table.checkStatus('tableList');
                    if (checkStatus.isAll) {
                        $('.layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
                        form.render('checkbox');
                    }
                }
            });
            //选中的人数
            table.on('checkbox(tableList)', function (obj) {
                if (obj.checked == true) {
                    if (obj.type == 'one') {
                        ids.push(obj.data.id);
                    } else {
                        for (let i = 0; i < tableIds.length; i++) {
                            if (ids.indexOf(tableIds[i]) == -1) {
                                ids.push(tableIds[i]);
                            }
                        }
                    }
                } else {
                    if (obj.type == 'one') {
                        let i = ids.length;
                        while (i--) {
                            if (ids[i] == obj.data.id) {
                                ids.splice(i, 1);
                            }
                        }
                    } else {
                        let i = ids.length;
                        while (i--) {
                            if (tableIds.indexOf(ids[i]) != -1) {
                                ids.splice(i, 1);
                            }
                        }
                    }
                }
                $('#amount').val(ids.length);
                memberArr = ids;
            })
        })
    })

    //筛选
    function query() {
        jsondata = {
            realName: $('#realName').val(),
            companyName: $("#companyId").val(),
            deptName: $("#deptId").val(),
            roleId: $("#roleId").val(),

        };
        table.reload('tableList', {where: jsondata});
    }
    //取消
    function closes(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    //添加
    function add(){
        // let ids=[];
        //
        // for(var i=0;i<memberArr.length;i++){
        //     ids.push(memberArr[i]);
        // }
        if (memberArr.length <= 0){
            layer.msg("请选择考生",{icon: 2});
            $("#amount").val(data.length);
            return false;
        }
        var json={
            ids:memberArr,
            examId:$("#examId").val()
        }
        layerAjaxGet("/exam/list/insertExStuExam",json,"",function (d) {
            var str;
            if(d.flag){
                if (601 == d.status && '' != d.data){
                    str = '用户 ';
                    for(var i=0;i<d.data.length;i++){
                        str += d.data[i].realName
                    }
                    layer.msg(str + " 添加失败,本次考试中已经存在此用户",{icon:2});
                }
                setTimeout(function (){
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                },3000)
            }else {
                layer.msg("操作失败!",{icon:2});
            }
        })
    }

</script>
</body>
</html>
